<%@page import="java.util.List"%>
<%@page import="com.wanmait.hotelManage.vo.Roomimages"%>
<%@page import="com.wanmait.hotelManage.vo.RoomType"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	String path=request.getContextPath();
%>
<%
	RoomType roomType=(RoomType)request.getAttribute("roomType");
	List<RoomType> roomTypes=(List<RoomType>)request.getAttribute("roomTypes");
	List<Roomimages> roomimages=(List<Roomimages>)request.getAttribute("roomTypeImages");
%>
<jsp:include page="/manage/inc/header.jsp"/>
<jsp:include page="/manage/inc/menu.jsp"></jsp:include>
 
    <!--/sidebar-->
    <div class="main-wrap">

        <div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"></i>
            <a href="<%=path%>/manage/index.jsp">首页</a><span class="crumb-step">&gt;</span>
            <a class="crumb-name" href="<%=path%>/manage/RoomTypeServlet?action=list">类型管理</a><span class="crumb-step">&gt;</span><span>修改房型</span></div>
        </div>
        <div class="result-wrap">
            <div class="result-content">
                <form action="<%=path %>/manage/RoomTypeServlet?action=update" method="post" id="myform" name="myform"  enctype="multipart/form-data">
                    <table class="insert-tab" width="100%">
                        <tbody>
                            <tr>
                                <th><i class="require-red">*</i>房型名称：</th>
                                <td>
                                     <input class="common-text required" id="title" name="title" size="20" value="<%=roomType.getTitle() %>" type="text"> 
                                 <%--    <select>
                                    	<option><%=roomType.getTitle() %></option>
                                    	<%
                                    		for(RoomType roomType2:roomTypes){
                                    			
	                                    %>
	                                    	<option>
	                                    		<%=roomType2.getTitle() %>
	                                    	</option>
	                                    <%	
                                    		}
                                    	 %>
                                    </select> --%>
                                </td>
                            </tr>
                            <tr>
                                <th><i class="require-red">*</i>原价：</th>
                                <td><input class="common-text" name="price" id="price" size="5" value="<%=roomType.getPrice() %>" type="text">
                                <input type="hidden" id="id" name="id" value="<%=roomType.getId()%>">
                                <span id="priceMsg"></span>
                                </td>
                            </tr>
                            <tr>
                                <th><i class="require-red">*</i>现价：</th>
                                <td><input class="common-text" id="discountPrice" name="discountPrice" size="5" value="<%=roomType.getDiscountPrice() %>" type="text">
                                <span id="discountPriceMsg"></span>
                                </td>
                            </tr>
                            <tr>
                                <th><i class="require-red">*</i>热门：</th>
                                <td><select name="hot" id="hot">
                                		<option id="ishot">热门</option>
                                		<option id="nothot">非热门</option>
                                	</select>
                                <span id="discountPriceMsg"></span>
                                </td>
                            </tr>
                            <tr>
                                <th><i class="require-red">*</i>封面图：</th>
                                <td><img id="pici" style="width: 100px;height: 70px;" name="<%=roomType.getPic() %>"
                                 src="<%=path%>/static/images/<%=roomType.getPic()%>">
                                <input style="width: 100px;height: 70px;" name="picture" id="pic" type="file"  onchange="reads(this)" ></td>
                            </tr>
                            
                            <!-- 轮播图图片开始 -->
                            
                            <tr>
                                <th><i class="require-red">*</i>轮播图：</th>
                                <td>
                               <%--  <%
                                	for(int i=0;i<2;i++){
                            	%> --%>
                            		<img id="im1" style="width: 100px;height: 70px;" name="<%=roomimages.get(0).getPic() %>"
                            		 src="<%=path%>/static/images/rooms/<%=roomimages.get(0).getPic()%>">
                               		<input name="pic<%=roomimages.get(0).getId() %>" id="images1" type="file"  onchange="reads1(this)">
                            		<img id="im2" style="width: 100px;height: 70px;" name="<%=roomimages.get(1).getPic() %>"
                            		 src="<%=path%>/static/images/rooms/<%=roomimages.get(1).getPic()%>">
                               		<input name="pic<%=roomimages.get(1).getId() %>" id="images2" type="file"  onchange="reads2(this)">
                            	<%-- <% 
                                	}
                                %> --%>
                                <br>
                                <%--  <%
                                	for(int i=2;i<4;i++){
                            	%> --%>
                            		<img id="im3" style="width: 100px;height: 70px;" name="<%=roomimages.get(2).getPic() %>"
                            		 src="<%=path%>/static/images/rooms/<%=roomimages.get(2).getPic()%>">
                               		<input name="pic<%=roomimages.get(2).getId() %>" id="images3" type="file"  onchange="reads3(this)">
                            		<img id="im4" style="width: 100px;height: 70px;" name="<%=roomimages.get(3).getPic() %>"
                            		 src="<%=path%>/static/images/rooms/<%=roomimages.get(3).getPic()%>">
                               		<input name="pic<%=roomimages.get(3).getId() %>" id="images4" type="file"  onchange="reads4(this)">
                            	<%-- <% 
                                	}
                                %> --%>
                                
                                <!--<input type="submit" onclick="submitForm('/jscss/admin/design/upload')" value="上传图片"/>-->
                                </td>
                            </tr>
                            
                            <!-- 轮播图图片结束 -->
                            <tr>
                                <th><i class="require-red">*</i>简介：</th>
                                <td><textarea name="description" class="common-textarea" id="content" cols="30" style="width: 98%;" rows="10"><%=roomType.getDescription() %></textarea></td>
                            </tr>
                            <tr>
                                <th></th>
                                <td>
                                    <input class="btn btn-primary btn6 mr10" value="提交" type="submit">
                                    <input class="btn btn6" onclick="history.go(-1)" value="返回" type="button">
                                </td>
                            </tr>
                        </tbody></table>
                </form>
            </div>
        </div>

    </div>
    <!--/main-->
</div>

<jsp:include page="/manage/inc/footer.jsp"/>
<script>

$(function() {
	 $("#im3").click(function() {
        $("#images3").click();
      });
	 $("#im2").click(function() {
        $("#images2").click();
      });
	 $("#im1").click(function() {
       $("#images1").click();
     });
	 $("#im4").click(function() {
        $("#images4").click();
      });
	 $("#pici").click(function() {
	   $("#pic").click();
	 });
	})
	function reads(obj) {
	 var file = obj.files[0];
	 var reader = new FileReader();
	 reader.readAsDataURL(file);
	 reader.onload = function(ev) {
	   $("#pici").attr("src",
	       ev.target.result);
	 }
	}
	
	 
	
	
	function reads1(obj) {
	 var file = obj.files[0];
	 var reader = new FileReader();
	 reader.readAsDataURL(file);
	 reader.onload = function(ev) {
	   $("#im1").attr("src",
	       ev.target.result);
	 }
	}
	
	
	
	
	function reads2(obj) {
	 var file = obj.files[0];
	 var reader = new FileReader();
	 reader.readAsDataURL(file);
	 reader.onload = function(ev) {
	   $("#im2").attr("src",
	       ev.target.result);
	 }
	}
	
	
	
	function reads3(obj) {
	 var file = obj.files[0];
	 var reader = new FileReader();
	 reader.readAsDataURL(file);
	 reader.onload = function(ev) {
	   $("#im3").attr("src",
	       ev.target.result);
	 }
	}
	
	
	function reads4(obj) {
	 var file = obj.files[0];
	 var reader = new FileReader();
	 reader.readAsDataURL(file);
	 reader.onload = function(ev) {
	   $("#im4").attr("src",
	       ev.target.result);
	 }
	}





	$(function() {
		//热门下拉列表框
		if(<%=roomType.getHot()%>){
			$("#ishot").prop("selected",true);
		}else{
			$("#nothot").prop("selected",true);
		}
		
		//原价验证
		$("#price").blur(function() {
			var price=$(this).val();
			var priceRe=/^\d+(\.\d+)?$/;
			if(!priceRe.test(price)){
				$("#priceMsg").html("您输入的价格有误,请重新输入");
				$(this).select();
			}else{
				$("#priceMsg").empty();
			}
		});
		//折扣价验证
		$("#discountPrice").blur(function() {
			var price=$(this).val();
			var priceRe=/^\d+(\.\d+)?$/;
			if(!priceRe.test(price)){
				$("#discountPriceMsg").html("您输入的价格有误,请重新输入");
				$(this).select();
			}else{
				$("#discountPriceMsg").empty();
			}
		});
		//提交按钮
		$("#subBtn").click(function() {
			var title=$.trim($("#title").val());
			if(title.length<2){
				$("#titleMsg").html("标题长度不能少于2个字符");
				$("#title").select();
				return;
			}else{
				$("#titleMsg").html("");
			}
			var description=$.trim($("#description").val());
			if(description.length<4){
				$("#descriptionMsg").html("简介长度不能少于4个字符");
				$("#description").select();
				return;
			}else {
				$("#descriptionMsg").html("");
			}
			
			$("#myform").submit();
			
		})
	})

</script>